package com.lin.mock.pay.server.task;

import com.lin.mock.pay.server.model.dto.OrderTaskDTO;
import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * @author: linjiang
 * @date: 2024/12/16
 */
@Component
public class TaskManager {

    private TaskExcutor excutor;

    public TaskManager() {
        excutor = new TaskExcutor();
    }

    /**
     * 支付成功/退款成功，向队列中添加元素
     */
    public void add(OrderTaskDTO task) {
        ConcurrentLinkedQueue<OrderTaskDTO> queue = excutor.getQueue();
        queue.offer(task);
    }

    /**
     * 启动任务
     */
    public void startTask() {
        new Thread(excutor).start();
    }
}
